From 4b74e7f2c1e5bbbabd62c4e816b4413037dc923f Mon Sep 17 00:00:00 2001 From: robertlipe Date: Fri, 23 Aug 2013 03:01:02 +0000 Subject: [PATCH] Whittle away a few more C-style date handlers. --- gpsbabel/exif.cc | 18 +++++++----------- gpsbabel/html.cc | 8 -------- gpsbabel/kml.cc | 9 +++------ gpsbabel/skyforce.cc | 14 ++++---------- gpsbabel/text.cc | 8 ++++---- 5 files changed, 18 insertions(+), 39 deletions(-) diff --git a/gpsbabel/exif.cc b/gpsbabel/exif.cc index 51c48af32..f449ffbc3 100644 --- a/gpsbabel/exif.cc +++ b/gpsbabel/exif.cc @@ -36,7 +36,6 @@ #include "defs.h" #include "garmin_tables.h" #include "jeeps/gpsmath.h" -#include "strptime.h" #define MYNAME "exif" @@ -649,8 +648,9 @@ exif_find_tag(exif_app_t* app, const uint16_t ifd_nr, const uint16_t tag_id) static time_t exif_get_exif_time(exif_app_t* app) { + QDateTime res; + exif_tag_t* tag; - time_t res = 0; tag = exif_find_tag(app, EXIF_IFD, 0x9003); /* DateTimeOriginal from EXIF */ if (! tag) { @@ -659,20 +659,15 @@ exif_get_exif_time(exif_app_t* app) if (! tag) { tag = exif_find_tag(app, EXIF_IFD, 0x9004); /* DateTimeDigitized from EXIF */ } + if (tag) { - struct tm tm; - char* c, *str; + char* str; - memset(&tm, 0, sizeof(tm)); str = exif_read_str(tag); - c = strptime(str, "%Y:%m:%d %H:%M:%S", &tm); - if (c && (*c == '\0')) { - res = mklocaltime(&tm); - } - + res = QDateTime::fromString(str, "yyyy:MM:dd hh:mm:ss"); xfree(str); } - return res; + return res.toTime_t(); } static waypoint* @@ -850,6 +845,7 @@ exif_waypt_from_exif_app(exif_app_t* app) } else { timestamp = datestamp; } + if (timestamp != UNKNOWN_TIMESTAMP) { #ifdef EXIF_DBG char* str = exif_time_str(timestamp); diff --git a/gpsbabel/html.cc b/gpsbabel/html.cc index b3688367e..12c4d65f1 100644 --- a/gpsbabel/html.cc +++ b/gpsbabel/html.cc @@ -79,9 +79,7 @@ wr_deinit(void) static void html_disp(const waypoint* wpt) { - char tbuf[1024]; char* cout; - time_t tm = wpt->GetCreationTime().toTime_t(); int32_t utmz; double utme, utmn; char utmzc; @@ -91,12 +89,6 @@ html_disp(const waypoint* wpt) GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude, &utme, &utmn, &utmz, &utmzc); - if (tm == 0) { - tm = time(NULL); - } - strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm)); - - gbfprintf(file_out, "\n
\n", wpt->shortname); gbfprintf(file_out, "\n"); gbfprintf(file_out, "

%s - ",(global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname); diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc index 91e3ce501..3aa5cf5d5 100644 --- a/gpsbabel/kml.cc +++ b/gpsbabel/kml.cc @@ -1890,8 +1890,6 @@ void kml_mt_array_schema(const char* field_name, const char* display_name, void kml_write(void) { - char import_time[100]; - time_t now; const global_trait* traits = get_traits(); // Parse options @@ -1920,16 +1918,15 @@ void kml_write(void) writer->writeStartElement("Document"); - now = current_time().toTime_t(); - strftime(import_time, sizeof(import_time), "%c", localtime(&now)); if (realtime_positioning) { writer->writeTextElement("name", "GPS position"); } else { writer->writeTextElement("name", "GPS device"); } - if (now) { - writer->writeTextElement("snippet", QString("Created ") + QString(import_time)); + if (current_time().isValid()) { + writer->writeTextElement("snippet", QString("Created ") + + current_time().toString()); } kml_write_AbstractView(); diff --git a/gpsbabel/skyforce.cc b/gpsbabel/skyforce.cc index 9c447d5e3..47a802a2a 100644 --- a/gpsbabel/skyforce.cc +++ b/gpsbabel/skyforce.cc @@ -26,7 +26,6 @@ #include #include "defs.h" -#include "strptime.h" #define MYNAME "skyforce" @@ -93,7 +92,6 @@ static waypoint* skyforce_parse_trk(const char* str) { char* cx; - struct tm tm; char buf[15]; int len; @@ -103,18 +101,14 @@ skyforce_parse_trk(const char* str) if (wpt == NULL) { return NULL; } - - memset(&tm, 0, sizeof(tm)); strncpy(buf, str + 2, sizeof(buf) - 1); buf[14] = 0; - cx = strptime(buf, "%d%m%y %H%M%S ", &tm); - if ((cx != NULL) && (*cx != '\0')) { - fatal(MYNAME ": Could not parse date string (%s - %s).\n", buf, cx); - } - - wpt->SetCreationTime(mkgmtime(&tm)); + QDateTime dt = QDateTime::fromString(buf, "ddMMyy hhmmss"); + dt.setTimeSpec(Qt::UTC); + dt = dt.addYears(100); + wpt->SetCreationTime(dt); len = strlen(str); if (len >= 45) { diff --git a/gpsbabel/text.cc b/gpsbabel/text.cc index 5221d4ca6..bc25f334f 100644 --- a/gpsbabel/text.cc +++ b/gpsbabel/text.cc @@ -96,8 +96,8 @@ static void text_disp(const waypoint* wpt) { int latint, lonint; - char tbuf[1024]; - time_t tm = wpt->GetCreationTime().toTime_t(); +// char tbuf[1024]; +// time_t tm = wpt->GetCreationTime().toTime_t(); int32_t utmz; double utme, utmn; char utmzc; @@ -118,12 +118,12 @@ text_disp(const waypoint* wpt) GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude, &utme, &utmn, &utmz, &utmzc); - +#if 0 if (tm == 0) { tm = time(NULL); } strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm)); - +#endif tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 0); if (wpt->altitude != unknown_alt) { xasprintf(&altout, " alt:%d", (int)((altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude)); -- 2.30.2